package com.example.springboot.modules.test.dao;

import com.example.springboot.modules.test.entity.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CountryDao {

    @Select("select * from test_country where country_id =#{countryId}")
    @Results(id = "countryResult",value = {
            @Result(column = "country_Id",property = "countryId"),
            @Result(column = "country_Id",
                    property = "cities",
                    javaType = List.class,
                    many=@Many(select = "com.example.springboot.modules.test.dao.CityDao.getCitiesByCountryId"))
    })
    Country getCountryByCountryId(int countryId);

    @Select("select * from test_country where country_name =#{countryName} limit 1")
    @ResultMap(value = "countryResult")
    Country getCountryByCountryName(String countryName);

}
